{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="{% static 'data_process/lib/layui-v2.5.4/css/layui.css' %}" media="all">
    <link rel="stylesheet" href="{% static 'data_process/css/public.css' %}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div>
            <form>
                {% csrf_token %}
            </form>
        </div>
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-verify="required" lay-reqtext="旧的密码不能为空"
                           placeholder="请输入旧的密码" value="" class="layui-input">
                    <tip>填写自己账号的旧的密码，如果忘记旧密码请联系超级管理员。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-verify="required" lay-reqtext="新的密码不能为空"
                           placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-verify="required" lay-reqtext="新的密码不能为空"
                           placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="{% static 'data_process/lib/layui-v2.5.4/layui.js' %}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data = data.field;
            if (data.new_password != data.again_password) {
                layer.msg('新密码和确认密码不一致', function () {
                });
                return false
            }
            layer.confirm(JSON.stringify(data), {
                title: '确认提交的信息',
                yes: function (index, layero) {
                    var csrf_token = $("input[name='csrfmiddlewaretoken']").val();
                    $.ajax({
                        url: '{% url 'user_change_password' %}',
                        type: "POST",
                        async: false,
                        dataType: "json",
                        data: {'data': data, 'csrfmiddlewaretoken': csrf_token},
                        success: function (data) {
                            res_status = data['res_status'];
                            if (res_status == 0) {
                                layer.msg('密码修改成功，请刷新页面之后重新登陆', function () {
                                   // window.location = '/';
                                });
                            } else {
                                layer.msg('密码修改失败,旧密码错误或者新密码和确认密码不一致', function () {
                                    {#window.location = '/';#}

                                });
                            }
                        },
                        error: function (data) {
                            alert("报错");
                        }
                    });
                    layer.close(index);
                }

            });
            return false;
        });

    });
</script>
</body>
</html>